<template>
  <div class="tudiliyongB" v-if="tdlyztghBData.length">
    <div class="tudiliyongB_top">
      <div class="tudiliyongB_top_text">
        选址与土地利用总体规划关系一栏表-b
      </div>
    </div>
    <div class="table">
      <el-table
        :data="tableDatas"
        border
        height="340"
        style="width: 100%; margin-top: 10px;"
        row-key="id"
        default-expand-all
        :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
      >
        <el-table-column
          prop="name.value"
          min-width="50px"
          align="center"
          label="建设用地管制分区"
        >
        </el-table-column>
        <el-table-column
          prop="areaHa"
          align="center"
          min-width="50px"
          :formatter="rounding2"
          label="面积(ha)"
        >
        </el-table-column>
        <el-table-column
          prop="areaMu"
          align="center"
          min-width="40px"
          :formatter="rounding"
          label="面积(亩)"
        >
        </el-table-column>
        <el-table-column
          prop="ratio"
          align="center"
          min-width="40px"
          label="占比(%)"
        >
        </el-table-column>
        <!-- <el-table-column
          prop="zhanbi"
          align="center"
          min-width="50px"
          label="占比"
        >
        </el-table-column> -->
      </el-table>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      // 获取到表格的数据
      tableDatas: [
        {
          areaHa: 0,
          areaH2: 0,
          areaMu: 0,
          ratio: 0,
          name: {
            key: "",
            value: "",
          },
        },
      ],

      // 总计
      allHa: 0,
      allMu: 0,
      allRatio: 0,
    };
  },
  methods: {
    // 接口请求关系表b数据
    getCunluoData() {
      let num = 0;
      this.tdlyztghBData.forEach((item, index) => {
        if (index < this.tdlyztghBData.length - 1) {
          num += Number(item.ratio);
        } else {
          item.ratio = Number((100 - num).toFixed(1));
        }
      });

      console.log(this.tdlyztghBData, "----tdlyztghBData的数据----");
      // this.tdlyztghBData[0].ratio = (
      //   100 -
      //   this.tdlyztghBData[2].ratio -
      //   this.tdlyztghBData[1].ratio
      // ).toFixed(1);
      this.tableDatas = this.tdlyztghBData;
      console.log(this.tableDatas, "B tableDatas的值");
      this.tableDatas.forEach((item) => {
        // console.log(item,"item的值");
        this.allHa += Number(item.areaHa);
        this.allMu += Number(item.areaMu);
        this.allRatio += Number(item.ratio);
      });
      if (Number(this.allRatio.toFixed(0)) > 100) {
        this.allRatio = 100;
      } else {
        this.allRatio = this.allRatio.toFixed(0);
      }
      let a = {
        areaHa: this.allHa,
        areaMu: this.allMu,
        ratio: this.allRatio,
        name: {
          key: "",
          value: "总计",
        },
      };
      this.tableDatas.push(a);
    },
    // 过滤小数
    rounding(row, colum) {
      return parseFloat(row[colum.property]).toFixed(2);
    },
    rounding1(row, colum) {
      return parseFloat(row[colum.property]).toFixed(1);
    },
    rounding2(row, colum) {
      return parseFloat(row[colum.property]).toFixed(3);
    },
  },
  computed: {
    ...mapState("Sjsx", ["tdlyztghBData"]),
  },
  watch: {},
  mounted() {
    this.getCunluoData();
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-table,
::v-deep .el-table__expanded-cell {
  background-color: rgba(14, 85, 238, 0.109) !important;
  border: 1px solid #466393cc;
}
::v-deep .el-table__body-wrapper {
  height: 280px !important;
}
// 滚动条的宽度
::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}
// 滚动条的滑块
::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  border-radius: 10px;
  background: linear-gradient(
    180deg,
    rgba(131, 166, 166, 0.1),
    rgba(131, 166, 166, 0.8),
    rgba(131, 166, 166, 0.1)
  );
}
// 滚动条里面的轨道(即背景颜色)
::v-deep .el-table__body-wrapper::-webkit-scrollbar-track {
  // background-color: #5b739b2b;
  background-color: rgba(41, 71, 89, 0.4);
}
::v-deep .el-table__header th,
::v-deep .el-table__header tr {
  // background-color: #17B3A3;

  color: #fff;
}
::v-deep .el-table th,
::v-deep .el-table tr,
::v-deep .el-table td {
  background-color: rgba(251, 251, 251, 0.109) !important;

  border: 0px solid #466393cc;
}
::v-deep .el-table__expand-icon {
  color: #fff;
}
/* 去掉中间数据的分割线 */
::v-deep .el-table__row > td {
  // border: 1px solid #466393cc;
}
/* 去掉上面的线 */
::v-deep .el-table th.is-leaf {
  // border: 1px solid #466393cc;
}
/* 去掉最下面的那一条线 */
::v-deep .el-table::before {
  height: 0px;
}
::v-deep .el-table__body tr {
  background-color: transparent !important;

  border: 1px solid #466393cc;
}
// .el-table__body tr:hover > td {
//     background-color: transparent !important;

//     border: 0px solid #134087;
// }
::v-deep .el-table td.el-table__cell,
::v-deep .el-table th.el-table__cell.is-leaf {
  border-bottom: 1px solid #466393cc;
  border-left: 1px solid #466393cc;
  font-size: 18px;
}
::v-deep .el-table--border th.el-table__cell.gutter:last-of-type {
  border-bottom: 1px solid #466393cc;
}
::v-deep .el-table--border .el-table__cell,
::v-deep
  .el-table__body-wrapper
  .el-table--border.is-scrolling-left
  ~ .el-table__fixed {
  border-right: 0px solid #ebeef5;
  color: #fff;
}
::v-deep .el-table--border::after,
::v-deep .el-table--group::after,
::v-deep .el-table::before {
  content: "";
  position: absolute;
  background-color: #466393cc;
  z-index: 1;
}
::v-deep .el-table th.el-table__cell > .cell {
  padding-left: 5px;
  padding-right: 5px;
}
.tudiliyongB {
  margin-bottom: 35px;
  .tudiliyongB_top {
    background: url("../../../../../assets/images/home/top.png");
    background-size: cover;
    margin-top: 10px;
    .tudiliyongB_top_text {
      padding-left: 16px;
      font-family: OPPOSans;
      font-style: normal;
      font-weight: normal;
      font-size: 20px;
      line-height: 24px;
      /* identical to box height */
      color: #ffffff;
    }
  }
}
</style>
